﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using IQKS.AWP.BusinessAccessLayer;
using IQKS.AWP.BusinessObject;
using System.Configuration;

public partial class home_CandidateFeeAllocation : System.Web.UI.Page
{
    string [] CandDetails=new string[4];
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["CandidateDetails"]!=null) 
            {
                ViewState["CandidateDetails"] = Session["CandidateDetails"];

                CandDetails = (string[])ViewState["CandidateDetails"];

                BindDropDownList(CandDetails);
                FillCandidateDetails(CandDetails);
            }
            txtTotalOutofExpenses.Text = ConfigurationManager.AppSettings["TotalOutOfExpenses"].ToString();
            txtIQKSManagerFees.Text  = ConfigurationManager.AppSettings["IQKSManagerFee"].ToString();
            txtPortalAdministrationFees.Text = ConfigurationManager.AppSettings["PortalAdministrationFee"].ToString();

            ddlLocation.DataSource = null;
            ddlLocation.Items.Clear();
            ddlLocation.Enabled = false;
            txtAssessorLocationFees.Text = null;
            txtAssessorLocationFees.Enabled = false;

            //change if partner id thru assessor etc loaded then enable location
            
            if (ddlResearchLeadAssessor.SelectedValue.ToString() != "0" && ddlResearchLeadAssessor.SelectedValue.ToString() != "" && ddlResearchLeadAssessor.SelectedValue.ToString() != String.Empty)
            {
                //DataTable dtAsFees = (DataTable)ViewState["AssessorFees"];
                //txtResearchLeadAssessorFees.Text = dtAsFees.Select("AssessorID=" + ddlResearchLeadAssessor.SelectedValue.ToString())[0].ItemArray[1].ToString();
                //calculateSUM();
                int vAssessor =Convert.ToInt32(ddlResearchLeadAssessor.SelectedValue);

                DataSet ds1 = GetAssessorLocationFees(vAssessor);
                if (ds1.Tables[0].Rows.Count > 0)
                {
                    ddlLocation.Enabled = true;
                    txtAssessorLocationFees.Enabled = true;
                    ddlLocation.DataSource = ds1.Tables[0];
                    ddlLocation.DataTextField = "Location";
                    ddlLocation.DataValueField = "Fees";
                    ddlLocation.DataBind();
                    ddlLocation.Items.Insert(0, new ListItem("-- Allocation Location --   ", "0"));
                }
            }


            }
            txtTotalFeesUSD.Attributes.Add("readonly", "readonly");
        txtTotalFeesINR.Attributes.Add("readonly", "readonly");
        txtCurrencyDate.Attributes.Add("readonly", "readonly");
    }
    #region "Reusable methods"
    protected void ClearForm()
    {
        //ddlModeratorAssessor.SelectedValue = "0";
        ddlResearchLeadAssessor.SelectedValue = "0";
        ddlAuditorAssessor.SelectedValue = "0";
        ddlIndustryExpert.SelectedValue = "0";
        ddlIQKSManager.SelectedValue = "0";
        ddlCurrencyType.SelectedValue = "0";

        //txtModeratorAssessorFees.Text = "";
        txtResearchLeadAssessorFees.Text = "";
        txtAuditorAssessorFees.Text = "";
        txtIndustryExpertFees.Text = "";
        txtIQKSManagerFees.Text = "";
        txtTotalOutofExpenses.Text = "";
        txtPortalAdministrationFees.Text = "";

        txtTotalFeesUSD.Text = "";
        txtTotalFeesINR.Text = "";
        txtCurrencyDate.Text = "";
        txtRate.Text = "";
        txtPortalAdministrationRemark.Text = "";

        //tdCURR0.Visible = false;
        //tdCURR1.Visible = false;
        //tdCURR2.Visible = false;
        //tdCURR3.Visible = false;

        ddlLocation.DataSource = null;
        ddlLocation.Items.Clear();
        ddlLocation.Enabled = false;
        txtAssessorLocationFees.Text = null;
        txtAssessorLocationFees.Enabled = false;
        txtAssessorLocalFees.Text = null;
        txtAssessorLocalFeesAmount.Text = null;
    }
    protected void calculateSUM()
    {
        double val = 0;
        if (txtIQKSManagerFees.Text != "")
        {
            val = val + Convert.ToDouble(txtIQKSManagerFees.Text);
        }
        if (txtIndustryExpertFees.Text != "")
        {
            val = val + Convert.ToDouble(txtIndustryExpertFees.Text);
        }
        if (txtAuditorAssessorFees.Text != "")
        {
            val = val + Convert.ToDouble(txtAuditorAssessorFees.Text);
        }
        if (txtResearchLeadAssessorFees.Text != "")
        {
            val = val + Convert.ToDouble(txtResearchLeadAssessorFees.Text);
        }
        //if (txtModeratorAssessorFees.Text != "")
        //{
        //    val = val + Convert.ToDouble(txtModeratorAssessorFees.Text);
        //}
        if (txtTotalOutofExpenses.Text != "")
        {
            val = val + Convert.ToDouble(txtTotalOutofExpenses.Text);
        }
        if (txtPortalAdministrationFees.Text != "")
        {
            val = val + Convert.ToDouble(txtPortalAdministrationFees.Text);
        }
        txtTotalFeesUSD.Text = Convert.ToString(val);
        if (txtRate.Text != "")
        {
            val = val * (Convert.ToDouble(txtRate.Text));
        }
        txtTotalFeesINR.Text = Convert.ToString(val);

        // local fees total calc
        if ((txtAssessorLocalFees.Text != "") && (txtAssessorLocationFees.Text != ""))
        {
            val = Convert.ToDouble(txtAssessorLocalFees.Text) + Convert.ToDouble(txtAssessorLocationFees.Text);
            txtAssessorLocalFeesAmount.Text = Convert.ToString(val);
        }

    }
    protected void FillCandidateDetails(string[] CandidateDetails)
    {
        lblCandidateName.Text = CandidateDetails[4].ToString() + " (" +  CandidateDetails[2].ToString() + ") ";
        lblCandidateType.Text = CandidateDetails[6].ToString();
        lblCountryName.Text = CandidateDetails[3].ToString();
        lblRegistrationNo.Text = CandidateDetails[1].ToString();
        lblCandidateType.Text=CandidateDetails[6].ToString();
    }
    protected void BindDropDownList(string[] CandidateDetails)
    {
        
        DataSet dsRARL = GetAssessorByRole("RARL", Convert.ToInt32(CandidateDetails[0]));
        ddlResearchLeadAssessor.DataSource = dsRARL.Tables[0];
        ddlResearchLeadAssessor.DataTextField = "AssessorName";
        ddlResearchLeadAssessor.DataValueField = "AssessorID";
        ddlResearchLeadAssessor.DataBind();
        ddlResearchLeadAssessor.Items.Insert(0, new ListItem("-- Allocate Assessor --   ", "0"));
        

        DataSet dsAD = GetAssessorByRole("AD", Convert.ToInt32(CandidateDetails[0]));
        ddlAuditorAssessor.DataSource = dsAD.Tables[0];
        ddlAuditorAssessor.DataTextField = "AssessorName";
        ddlAuditorAssessor.DataValueField = "AssessorID";
        ddlAuditorAssessor.DataBind();
        ddlAuditorAssessor.Items.Insert(0, new ListItem("-- Allocate Auditor --   ", "0"));

        DataSet dsIE = GetAssessorByRole("IE", Convert.ToInt32(CandidateDetails[0]));
        ddlIndustryExpert.DataSource = dsIE.Tables[0];
        ddlIndustryExpert.DataTextField = "AssessorName";
        ddlIndustryExpert.DataValueField = "AssessorID";
        ddlIndustryExpert.DataBind();
        ddlIndustryExpert.Items.Insert(0, new ListItem("-- Allocate Industry Expert --   ", "0"));

        DataSet dsIQKSMG = GetAssessorByRole("IQKSMG", Convert.ToInt32(CandidateDetails[0]));
        ddlIQKSManager.DataSource = dsIQKSMG.Tables[0];
        ddlIQKSManager.DataTextField = "AssessorName";
        ddlIQKSManager.DataValueField = "AssessorID";
        ddlIQKSManager.DataBind();
        ddlIQKSManager.Items.Insert(0, new ListItem("-- Allocate IQKS Manager --   ", "0"));

        ddlCurrencyType.DataSource = dsIQKSMG.Tables[2];
        ddlCurrencyType.DataTextField = "ActivityName";
        ddlCurrencyType.DataValueField = "ActivityID";
        ddlCurrencyType.DataBind();
        ddlCurrencyType.Items.Insert(0, new ListItem("-- Select Currency Type --   ", "0"));

        ddlAssessorLocalFeesCurrency.DataSource = dsIQKSMG.Tables[2];
        ddlAssessorLocalFeesCurrency.DataTextField = "ActivityName";
        ddlAssessorLocalFeesCurrency.DataValueField = "ActivityID";
        ddlAssessorLocalFeesCurrency.DataBind();
        ddlAssessorLocalFeesCurrency.Items.Insert(0, new ListItem("Select Currency", "0"));


        //todo
        if (Convert.ToInt64(CandidateDetails[7]) > 0)
        {
            DataSet objPartnerDs;
            objPartnerDs = new CandidateAllocateAssessorBAL().GetPartnerAssessor(Convert.ToInt64(CandidateDetails[7]), Convert.ToInt32(CandidateDetails[0]));

            decimal deTotalFess = 0;


            //ddlResearchLeadAssessor.SelectedIndex = ddlResearchLeadAssessor.
            if (objPartnerDs.Tables.Count > 0)
            { 
                for (int i=0 ; i <  objPartnerDs.Tables[0].Rows.Count; i++)
                {
                    if (Convert.ToString(objPartnerDs.Tables[0].Rows[i]["RoleName"]) == "RARL")
                    {
                        ddlResearchLeadAssessor.Enabled = false;
                        ddlResearchLeadAssessor.SelectedIndex = ddlResearchLeadAssessor.Items.IndexOf(ddlResearchLeadAssessor.Items.FindByValue(Convert.ToString(objPartnerDs.Tables[0].Rows[i]["AssessorID"])));
                        txtResearchLeadAssessorFees.Text = Convert.ToString(objPartnerDs.Tables[0].Rows[i]["Fees"]);
                        deTotalFess =  deTotalFess +  Convert.ToDecimal(objPartnerDs.Tables[0].Rows[i]["Fees"]);
                    }
                    else if (Convert.ToString(objPartnerDs.Tables[0].Rows[i]["RoleName"]) == "AD")
                    {
                        ddlAuditorAssessor.Enabled = false;
                        ddlAuditorAssessor.SelectedIndex = ddlAuditorAssessor.Items.IndexOf(ddlAuditorAssessor.Items.FindByValue(Convert.ToString(objPartnerDs.Tables[0].Rows[i]["AssessorID"])));
                        txtAuditorAssessorFees.Text = Convert.ToString(objPartnerDs.Tables[0].Rows[i]["Fees"]);
                        deTotalFess =  deTotalFess +  Convert.ToDecimal(objPartnerDs.Tables[0].Rows[i]["Fees"]);
                    }
                    else if (Convert.ToString(objPartnerDs.Tables[0].Rows[i]["RoleName"]) == "IE")
                    {
                        ddlIndustryExpert.Enabled = false;
                        ddlIndustryExpert.SelectedIndex = ddlIndustryExpert.Items.IndexOf(ddlIndustryExpert.Items.FindByValue(Convert.ToString(objPartnerDs.Tables[0].Rows[i]["AssessorID"])));
                        txtIndustryExpertFees.Text = Convert.ToString(objPartnerDs.Tables[0].Rows[i]["Fees"]);
                        deTotalFess =  deTotalFess +  Convert.ToDecimal(objPartnerDs.Tables[0].Rows[i]["Fees"]);
                    }
                }

                txtTotalFeesUSD.Text = Convert.ToString(deTotalFess);
                txtTotalFeesINR.Text = Convert.ToString(deTotalFess);
            }

        }

    }
    private DataSet GetAssessorByRole(string strRoleName, int Candidateid)
    {
        DataSet objDs;
        objDs = new UserMasterBAL().GetAssessorByRole(strRoleName, Candidateid);
        if (objDs.Tables.Count > 1)
        {
            if (ViewState["AssessorFees"] == null)
            {
                ViewState["AssessorFees"] = objDs.Tables[1];
            }
        }
        return objDs;
    }
    private DataSet GetAssessorLocationFees( int Assessorid)
    {
        DataSet objDs;
        objDs = new UserMasterBAL().GetAssessorLocationFees( Assessorid);
        /*if (objDs.Tables.Count > 1)
        {
            if (ViewState["AssessorLocationFees"] == null)
            {
                ViewState["AssessorLocationFees"] = objDs.Tables[1];
            }
        }*/
        return objDs;
    }
    #endregion

    #region "Button events"
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            CandidateAllocateAssessorBAL objCABal = new CandidateAllocateAssessorBAL();
            CandidateAllocateAssessorBO objCABO = new CandidateAllocateAssessorBO();

            //if (ddlModeratorAssessor.SelectedValue != "")
            //{
            //    objCABO.ModeratorID = Convert.ToInt32(ddlModeratorAssessor.SelectedValue);
            //    objCABO.ModeratorFees = (double)Convert.ToDouble(txtModeratorAssessorFees.Text.Trim());
            //}
            //else
            //{
               objCABO.ModeratorID = 0;
               objCABO.ModeratorFees = 0.00;
            //}
            //if (ddlResearchLeadAssessor.SelectedValue != "")
            //{
                objCABO.ResearchLeadID = Convert.ToInt32(ddlResearchLeadAssessor.SelectedValue);
                objCABO.ResearchLeadFees = (double)Convert.ToDouble(txtResearchLeadAssessorFees.Text.Trim());
            //}
            //else
            //{
            //    objCABO.ResearchLeadID = 0;
            //    objCABO.ResearchLeadFees = 0.00;
            //}
            objCABO.AuditorID = Convert.ToInt32(ddlAuditorAssessor.SelectedValue);
            objCABO.IndustryExpertID = Convert.ToInt32(ddlIndustryExpert.SelectedValue);
            objCABO.AuditorFees = (double)Convert.ToDouble(txtAuditorAssessorFees.Text.Trim());
            objCABO.IndustryExpertFees = (double)Convert.ToDouble(txtIndustryExpertFees.Text.Trim());

            objCABO.IQKSManagerID = Convert.ToInt32(0);//ddlIQKSManager.SelectedValue);
            objCABO.IQKSManagerFees = (double)Convert.ToDouble(txtIQKSManagerFees.Text.Trim());

            if (ddlCurrencyType.SelectedValue != "0")
            {
                objCABO.CurrencyTypeID = Convert.ToInt32(ddlCurrencyType.SelectedValue);
                objCABO.CurrencyDate = txtCurrencyDate.Text.Trim();
                objCABO.CurrencyRate = Convert.ToDouble(txtRate.Text.Trim());
            }

            objCABO.TotalFees = Convert.ToDouble(txtTotalFeesUSD.Text.Trim());
            objCABO.GrossTotalFees = Convert.ToDouble(txtTotalFeesINR.Text.Trim());
            objCABO.PortalAdministrationExpenses = Convert.ToDouble(txtPortalAdministrationFees.Text.Trim());
            objCABO.TotalOutExpenses = Convert.ToDouble(txtTotalOutofExpenses.Text.Trim());
            objCABO.PortalAdministrationRemark = txtPortalAdministrationRemark.Text.Trim();

            objCABO.AssessorLocalFeesCurrency = Convert.ToInt32(ddlAssessorLocalFeesCurrency.SelectedValue);
            if (objCABO.AssessorLocalFeesCurrency != 0)
            {
                objCABO.AssessorLocalFees = Convert.ToDecimal(txtAssessorLocalFees.Text);
                if (txtAssessorLocationFees.Text != "")
                    objCABO.AssessorLocationFeesAmount = Convert.ToDecimal(txtAssessorLocationFees.Text);
                objCABO.AssessorLocalFeesAmount = Convert.ToDecimal(txtAssessorLocalFeesAmount.Text);
                if (ddlLocation.SelectedIndex > 0)
                    objCABO.AssessorLocation = ddlLocation.SelectedItem.Text;


            }

            CandDetails = (string[])ViewState["CandidateDetails"];
            objCABO.CandidateID = Convert.ToInt32(CandDetails[0]);
            objCABO.UserID = new Guid(CandDetails[5]);

            string EncryptedCandidateID = CommonUtility.Encrypt(Convert.ToString(objCABO.CandidateID),true);
            string ApproveStatusID = CommonUtility.Encrypt("25",true);
            string RejectStatusID = CommonUtility.Encrypt("26",true);

            string strReturnValue = (string)objCABal.SetCandidateAllocatedAssessor(objCABO,EncryptedCandidateID,ApproveStatusID,RejectStatusID);
            //string strReturnValue = "SUCCESS";
            if (strReturnValue == "SUCCESS")
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Assessors allocated successfully.'); ", true);
                ClearForm();
                lblCandidateName.Text = "";
                lblCandidateType.Text = "";
                lblCountryName.Text = "";
                lblRegistrationNo.Text = "";
                btnSave.Visible = false;
                //Page.ClientScript.RegisterStartupScript(this.GetType(), "CLOSE", "window.close();", true);
            }
        }
    }
    protected void btnClear_Click(object sender, EventArgs e)
    {
        ClearForm();
    }
    #endregion

    #region "Dropdownlist events"
    //protected void ddlModeratorAssessor_SelectedIndexChanged(object sender, EventArgs e)
    //{
    //    if (ddlModeratorAssessor.SelectedValue.ToString()!="0")
    //    {
    //        DataTable dtAsFees = (DataTable)ViewState["AssessorFees"];
    //        txtModeratorAssessorFees.Text = dtAsFees.Select("AssessorID=" + ddlModeratorAssessor.SelectedValue.ToString())[0].ItemArray[1].ToString();
    //        calculateSUM();
    //    }
    //}
    protected void ddlResearchLeadAssessor_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlResearchLeadAssessor.SelectedValue.ToString() != "0")
        {
            DataTable dtAsFees = (DataTable)ViewState["AssessorFees"];
            txtResearchLeadAssessorFees.Text = dtAsFees.Select("AssessorID=" + ddlResearchLeadAssessor.SelectedValue.ToString())[0].ItemArray[1].ToString();
            calculateSUM();

            DataSet ds1 = GetAssessorLocationFees(Convert.ToInt32(ddlResearchLeadAssessor.SelectedValue));
            if (ds1.Tables[0].Rows.Count>0)
            {
                ddlLocation.Enabled = true;
                txtAssessorLocationFees.Enabled = true;
                ddlLocation.DataSource = ds1.Tables[0];
                ddlLocation.DataTextField = "Location";
                ddlLocation.DataValueField = "Fees";
                ddlLocation.DataBind();
                ddlLocation.Items.Insert(0, new ListItem("-- Allocation Location --   ", "0"));
            }
            else
            {
                ddlLocation.DataSource = null;
                ddlLocation.Items.Clear();
                ddlLocation.Enabled = false;
                txtAssessorLocationFees.Text = null;
                txtAssessorLocationFees.Enabled = false;
            }
        }else
        {
            ddlLocation.DataSource = null;
            ddlLocation.Items.Clear();
            ddlLocation.Enabled = false;
            txtAssessorLocationFees.Text = null;
            txtAssessorLocationFees.Enabled = false;
        }
    }
    protected void ddlAuditorAssessor_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlAuditorAssessor.SelectedValue.ToString() != "0")
        {
            DataTable dtAsFees = (DataTable)ViewState["AssessorFees"];
            txtAuditorAssessorFees.Text = dtAsFees.Select("AssessorID=" + ddlAuditorAssessor.SelectedValue.ToString())[0].ItemArray[1].ToString();
            calculateSUM();
        }
    }
    protected void ddlIndustryExpert_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlIndustryExpert.SelectedValue.ToString() != "0")
        {
            DataTable dtAsFees = (DataTable)ViewState["AssessorFees"];
            txtIndustryExpertFees.Text = dtAsFees.Select("AssessorID=" + ddlIndustryExpert.SelectedValue.ToString())[0].ItemArray[1].ToString();
            calculateSUM();
        }
    }
    protected void ddlIQKSManager_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlIQKSManager.SelectedValue.ToString() != "0")
        {
            DataTable dtAsFees = (DataTable)ViewState["AssessorFees"];
            txtIQKSManagerFees.Text = dtAsFees.Select("AssessorID=" + ddlIQKSManager.SelectedValue.ToString())[0].ItemArray[1].ToString();
            calculateSUM();
        }
    }
    protected void ddlCurrencyType_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlCurrencyType.SelectedValue != "0")
        {
            //tdCURR0.Visible = false;
            //tdCURR1.Visible = true;
            //tdCURR2.Visible = true;
            //tdCURR3.Visible = true;
            trDateRow.Visible = true;
            lblCurrencyCode.Text = ddlCurrencyType.SelectedItem.Text;
        }
        else
        {
            trDateRow.Visible = false;
            //tdCURR0.Visible = false;
            //tdCURR1.Visible = false;
            //tdCURR2.Visible = false;
            //tdCURR3.Visible = false;
            txtTotalFeesINR.Text = txtTotalFeesUSD.Text;
            txtRate.Text = "";
            txtCurrencyDate.Text = "";
            lblCurrencyCode.Text = "";
        }
    }
    #endregion
    //protected void txtModeratorAssessorFees_TextChanged(object sender, EventArgs e)
    //{
    //    if (Page.IsValid)
    //    {
    //        string strModFees = txtModeratorAssessorFees.Text.Trim();
    //        bool contains = strModFees.Contains(".");
           
    //        if (contains)
    //        {
    //            string[] ModFeeDecimals = strModFees.Split('.');
    //            string beforedecimal = "00", afterdecimal = "00";
    //            if (ModFeeDecimals[0].Length == 0)
    //            { beforedecimal = "00"; }
    //            if (ModFeeDecimals[0].Length == 1)
    //            { beforedecimal = "0" + ModFeeDecimals[0]; }
    //            if (ModFeeDecimals[0].Length >1)
    //            { beforedecimal = ModFeeDecimals[0]; }

    //            if (ModFeeDecimals[1].Length == 0)
    //            { afterdecimal = "00"; }
    //            if (ModFeeDecimals[1].Length == 1)
    //            { afterdecimal = ModFeeDecimals[1] + "0"; }
    //            if (ModFeeDecimals[1].Length == 2)
    //            { afterdecimal = ModFeeDecimals[1]; }


    //            txtModeratorAssessorFees.Text = beforedecimal + "." + afterdecimal;
    //        }
    //        else
    //        {
    //            int lenAssesorModFee = strModFees.Length;
    //            if (lenAssesorModFee >1 )
    //            {
    //                txtModeratorAssessorFees.Text = strModFees + ".00";
    //            }
    //            if (lenAssesorModFee == 1)
    //            {
    //                txtModeratorAssessorFees.Text = "0" + strModFees + ".00";
    //            }
    //        }
    //    }
    //}
    protected void txtResearchLeadAssessorFees_TextChanged(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            string strModFees = txtResearchLeadAssessorFees.Text.Trim();
            bool contains = strModFees.Contains(".");

            if (contains)
            {
                string[] ModFeeDecimals = strModFees.Split('.');
                string beforedecimal = "00", afterdecimal = "00";
                if (ModFeeDecimals[0].Length == 0)
                { beforedecimal = "00"; }
                if (ModFeeDecimals[0].Length == 1)
                { beforedecimal = "0" + ModFeeDecimals[0]; }
                if (ModFeeDecimals[0].Length >1 )
                { beforedecimal = ModFeeDecimals[0]; }

                if (ModFeeDecimals[1].Length == 0)
                { afterdecimal = "00"; }
                if (ModFeeDecimals[1].Length == 1)
                { afterdecimal = ModFeeDecimals[1] + "0"; }
                if (ModFeeDecimals[1].Length == 2)
                { afterdecimal = ModFeeDecimals[1]; }


                txtResearchLeadAssessorFees.Text = beforedecimal + "." + afterdecimal;
            }
            else
            {
                int lenAssesorModFee = strModFees.Length;
                if (lenAssesorModFee >1)
                {
                    txtResearchLeadAssessorFees.Text = strModFees + ".00";
                }
                if (lenAssesorModFee == 1)
                {
                    txtResearchLeadAssessorFees.Text = "0" + strModFees + ".00";
                }
            }
        }
    }
    protected void txtAuditorAssessorFees_TextChanged(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            string strModFees = txtAuditorAssessorFees.Text.Trim();
            bool contains = strModFees.Contains(".");

            if (contains)
            {
                string[] ModFeeDecimals = strModFees.Split('.');
                string beforedecimal = "00", afterdecimal = "00";
                if (ModFeeDecimals[0].Length == 0)
                { beforedecimal = "00"; }
                if (ModFeeDecimals[0].Length == 1)
                { beforedecimal = "0" + ModFeeDecimals[0]; }
                if (ModFeeDecimals[0].Length >1)
                { beforedecimal = ModFeeDecimals[0]; }

                if (ModFeeDecimals[1].Length == 0)
                { afterdecimal = "00"; }
                if (ModFeeDecimals[1].Length == 1)
                { afterdecimal = ModFeeDecimals[1] + "0"; }
                if (ModFeeDecimals[1].Length == 2)
                { afterdecimal = ModFeeDecimals[1]; }


                txtAuditorAssessorFees.Text = beforedecimal + "." + afterdecimal;
            }
            else
            {
                int lenAssesorModFee = strModFees.Length;
                if (lenAssesorModFee >1 )
                {
                    txtAuditorAssessorFees.Text = strModFees + ".00";
                }
                if (lenAssesorModFee == 1)
                {
                    txtAuditorAssessorFees.Text = "0" + strModFees + ".00";
                }
            }
        }
    }
    protected void txtIndustryExpertFees_TextChanged(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            string strModFees = txtIndustryExpertFees.Text.Trim();
            bool contains = strModFees.Contains(".");

            if (contains)
            {
                string[] ModFeeDecimals = strModFees.Split('.');
                string beforedecimal = "00", afterdecimal = "00";
                if (ModFeeDecimals[0].Length == 0)
                { beforedecimal = "00"; }
                if (ModFeeDecimals[0].Length == 1)
                { beforedecimal = "0" + ModFeeDecimals[0]; }
                if (ModFeeDecimals[0].Length > 1)
                { beforedecimal = ModFeeDecimals[0]; }

                if (ModFeeDecimals[1].Length == 0)
                { afterdecimal = "00"; }
                if (ModFeeDecimals[1].Length == 1)
                { afterdecimal = ModFeeDecimals[1] + "0"; }
                if (ModFeeDecimals[1].Length == 2)
                { afterdecimal = ModFeeDecimals[1]; }


                txtIndustryExpertFees.Text = beforedecimal + "." + afterdecimal;
            }
            else
            {
                int lenAssesorModFee = strModFees.Length;
                if (lenAssesorModFee >1)
                {
                    txtIndustryExpertFees.Text = strModFees + ".00";
                }
                if (lenAssesorModFee == 1)
                {
                    txtIndustryExpertFees.Text = "0" + strModFees + ".00";
                }
            }
        }
    }
    protected void txtIQKSManagerFees_TextChanged(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            string strModFees = txtIQKSManagerFees.Text.Trim();
            bool contains = strModFees.Contains(".");

            if (contains)
            {
                string[] ModFeeDecimals = strModFees.Split('.');
                string beforedecimal = "00", afterdecimal = "00";
                if (ModFeeDecimals[0].Length == 0)
                { beforedecimal = "00"; }
                if (ModFeeDecimals[0].Length == 1)
                { beforedecimal = "0" + ModFeeDecimals[0]; }
                if (ModFeeDecimals[0].Length > 1)
                { beforedecimal = ModFeeDecimals[0]; }

                if (ModFeeDecimals[1].Length == 0)
                { afterdecimal = "00"; }
                if (ModFeeDecimals[1].Length == 1)
                { afterdecimal = ModFeeDecimals[1] + "0"; }
                if (ModFeeDecimals[1].Length == 2)
                { afterdecimal = ModFeeDecimals[1]; }


                txtIQKSManagerFees.Text = beforedecimal + "." + afterdecimal;
            }
            else
            {
                int lenAssesorModFee = strModFees.Length;
                if (lenAssesorModFee > 1)
                {
                    txtIQKSManagerFees.Text = strModFees + ".00";
                }
                if (lenAssesorModFee == 1)
                {
                    txtIQKSManagerFees.Text = "0" + strModFees + ".00";
                }
            }
        }
    }
    protected void txtTotalOutofExpenses_TextChanged(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            string strModFees = txtTotalOutofExpenses.Text.Trim();
            bool contains = strModFees.Contains(".");

            if (contains)
            {
                string[] ModFeeDecimals = strModFees.Split('.');
                string beforedecimal = "00", afterdecimal = "00";
                if (ModFeeDecimals[0].Length == 0)
                { beforedecimal = "00"; }
                if (ModFeeDecimals[0].Length == 1)
                { beforedecimal = "0" + ModFeeDecimals[0]; }
                if (ModFeeDecimals[0].Length > 1)
                { beforedecimal = ModFeeDecimals[0]; }

                if (ModFeeDecimals[1].Length == 0)
                { afterdecimal = "00"; }
                if (ModFeeDecimals[1].Length == 1)
                { afterdecimal = ModFeeDecimals[1] + "0"; }
                if (ModFeeDecimals[1].Length == 2)
                { afterdecimal = ModFeeDecimals[1]; }


                txtTotalOutofExpenses.Text = beforedecimal + "." + afterdecimal;
            }
            else
            {
                int lenAssesorModFee = strModFees.Length;
                if (lenAssesorModFee > 1)
                {
                    txtTotalOutofExpenses.Text = strModFees + ".00";
                }
                if (lenAssesorModFee == 1)
                {
                    txtTotalOutofExpenses.Text = "0" + strModFees + ".00";
                }
            }
        }
    }
    protected void txtPortalAdministrationFees_TextChanged(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            string strModFees = txtPortalAdministrationFees.Text.Trim();
            bool contains = strModFees.Contains(".");

            if (contains)
            {
                string[] ModFeeDecimals = strModFees.Split('.');
                string beforedecimal = "00", afterdecimal = "00";
                if (ModFeeDecimals[0].Length == 0)
                { beforedecimal = "00"; }
                if (ModFeeDecimals[0].Length == 1)
                { beforedecimal = "0" + ModFeeDecimals[0]; }
                if (ModFeeDecimals[0].Length > 1)
                { beforedecimal = ModFeeDecimals[0]; }

                if (ModFeeDecimals[1].Length == 0)
                { afterdecimal = "00"; }
                if (ModFeeDecimals[1].Length == 1)
                { afterdecimal = ModFeeDecimals[1] + "0"; }
                if (ModFeeDecimals[1].Length == 2)
                { afterdecimal = ModFeeDecimals[1]; }


                txtPortalAdministrationFees.Text = beforedecimal + "." + afterdecimal;
            }
            else
            {
                int lenAssesorModFee = strModFees.Length;
                if (lenAssesorModFee > 1)
                {
                    txtPortalAdministrationFees.Text = strModFees + ".00";
                }
                if (lenAssesorModFee == 1)
                {
                    txtPortalAdministrationFees.Text = "0" + strModFees + ".00";
                }
            }
        }
    }
    protected void txtTotalFeesUSD_TextChanged(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            string strModFees = txtTotalFeesUSD.Text.Trim();
            bool contains = strModFees.Contains(".");

            if (contains)
            {
                string[] ModFeeDecimals = strModFees.Split('.');
                string beforedecimal = "00", afterdecimal = "00";
                if (ModFeeDecimals[0].Length == 0)
                { beforedecimal = "00"; }
                if (ModFeeDecimals[0].Length == 1)
                { beforedecimal = "0" + ModFeeDecimals[0]; }
                if (ModFeeDecimals[0].Length > 1)
                { beforedecimal = ModFeeDecimals[0]; }

                if (ModFeeDecimals[1].Length == 0)
                { afterdecimal = "00"; }
                if (ModFeeDecimals[1].Length == 1)
                { afterdecimal = ModFeeDecimals[1] + "0"; }
                if (ModFeeDecimals[1].Length == 2)
                { afterdecimal = ModFeeDecimals[1]; }


                txtTotalFeesUSD.Text = beforedecimal + "." + afterdecimal;
            }
            else
            {
                int lenAssesorModFee = strModFees.Length;
                if (lenAssesorModFee > 1)
                {
                    txtTotalFeesUSD.Text = strModFees + ".00";
                }
                if (lenAssesorModFee == 1)
                {
                    txtTotalFeesUSD.Text = "0" + strModFees + ".00";
                }
            }
        }

    }



    protected void ddlLocation_SelectedIndexChanged(object sender, EventArgs e)
    {
        txtAssessorLocationFees.Text = ddlLocation.SelectedValue;
        calculateSUM();
    }

    protected void ddlAssessorLocalFeesCurrency_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlAssessorLocalFeesCurrency.SelectedIndex!=0)
        {
            lblLocalCurrencyCode.Text = ddlAssessorLocalFeesCurrency.SelectedItem.Text;
        }
        else
        {
            lblLocalCurrencyCode.Text = null;
        }
    }
}